package at.ltasat.train.set;

import java.io.IOException;
import java.io.InputStream;

import at.ltasat.ArgumentClazzData;
import at.ltasat.classifier.Classifier;
import at.ltasat.classifier.ClassifierFactory;
import at.ltasat.classifier.ClazzManager;
import at.ltasat.classifier.ObjectFeatures;
import at.ltasat.classifier.ObjectFeaturesFactory;
import at.ltasat.classifier.Trainer;

public final class ManualClassifierFactory implements ClassifierFactory<byte[], ArgumentClazzData> {

	private static final String NAME = "manual";

	private final int nIterations;
	private final long maxTime;

	public ManualClassifierFactory(int nIterations, long maxTime) {
		if (nIterations < 1) {
			throw new IllegalArgumentException("Number of iterations must be greater than zero!");
		}
		if (maxTime < 0) {
			throw new IllegalArgumentException("Maximum time must be greater or equal to zero!");
		}
		this.nIterations = nIterations;
		this.maxTime = maxTime;
	}

	@Override
	public String getName() {
		return NAME;
	}

	@Override
	public Trainer<byte[], ArgumentClazzData> createTrainer(ClazzManager<ArgumentClazzData> classes, ObjectFeaturesFactory<byte[]> factory) {
		return new ManualTrainer(NAME, classes, new MyFactory(), nIterations, maxTime);
	}

	@Override
	public Classifier<byte[], ArgumentClazzData> readClassifier(ClazzManager<ArgumentClazzData> classes, ObjectFeaturesFactory<byte[]> factory, InputStream in) throws IOException {
		return createTrainer(classes, new MyFactory()).create();
	}

	private static final class MyFactory implements ObjectFeaturesFactory<byte[]> {

		@Override
		public int getNumberOfFeatures() {
			return 0;
		}

		@Override
		public ObjectFeatures create(byte[] object) {
			return new ObjectFeatures(new double[0]);
		}

	}

}
